<template>
  <div class="list-table">
    <div class=" area-header">
      <span class="area-header-title">{{ $t('出差申请') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('申请标题')" prop="actTitle">
        <el-input v-model="queryParams.actTitle" size="small" :placeholder="$t('申请标题')" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('申请人')" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          size="small"
          :placeholder="$t('申请人')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('出差类型')" prop="type">
        <el-select v-model="queryParams.type" size="small" clearable :placeholder="$t('请选择')">
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <!--      <el-form-item :label="$t('出发地')" prop="placeDeparture">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.placeDeparture"-->
      <!--          size="small"-->
      <!--          :placeholder="$t('出发地')"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="queryHandle"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item :label="$t('目的地类型')" prop="destination">
        <dictSelect
          v-model="queryParams.destination"
          :clearable="true"
          dictionary="destination_type"
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:travel:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:travel:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="oaBusinessTravelList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="center" prop="actTitle" :show-overflow-tooltip="true" min-width="200">
        <template slot-scope="scope">
          <el-link type="primary" @click="updateHandle(scope.row)">{{ scope.row.actTitle }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请人')" align="center" prop="nickName" width="110" />
      <el-table-column :label="$t('申请时间')" align="center" prop="applyTime" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请部门')" align="center" prop="deptName" width="110" />
      <el-table-column :label="$t('出差类型')" align="center" :formatter="typeFormat" prop="type" width="110" show-overflow-tooltip />
      <el-table-column :label="$t('出差方式')" align="center" prop="methodLabel" width="100" show-overflow-tooltip />
      <el-table-column :label="$t('目的地类型')" align="center" prop="destination" :formatter="destinationFormat" width="100" show-overflow-tooltip />
      <el-table-column :label="$t('时间')" align="center" prop="goOff" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.goOff) }} / {{ parseTime(scope.row.endTimes) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('审批状态')" align="center" fixed="right" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" fixed="right" width="200px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <ListBtn :bus-data="scope.row" :apply="scope.row.createBy.id" has-permi="oa:travel" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改出差申请对话框 -->
    <el-dialog v-el-drag-dialog :title="$t(title)" :visible.sync="formOpen" width="70%" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm">
      <oaBusinessTravelForm ref="oaBusinessTravelForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listOaBusinessTravel, delOaBusinessTravel } from '@/api/oa/travel/oaTravel'
import oaBusinessTravelForm from './oaTravelForm.vue'
export default {
    components: {
        oaBusinessTravelForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 出差申请表格数据
          oaBusinessTravelList: [],
          // 弹出层标题
          title: '出差申请',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              pageNum: 1,
              pageSize: 10,
              userId: undefined,
              nickName: undefined,
              type: undefined,
              placeDeparture: undefined,
              destination: undefined
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          },
          // 出差类型
          typeOptions: [],
          // 出差方式
          methodsOptions: [],
        // 目的地泪下
        destinations: []
      }
  },
  created() {
      this.getList()
      this.initDict()
  },
  methods: {
    typeFormat(row) {
				return this.$t(this.selectDictLabel(this.typeOptions, row.type))
    },
    methodFormat(row) {
				return this.$t(this.selectDictLabel(this.methodsOptions, row.method))
		},
    destinationFormat(row) {
      return this.$t(this.selectDictLabel(this.destinations, row.destination))
    },
    /** 查询出差申请列表 */
    getList() {
        this.loading = true
        listOaBusinessTravel(this.queryParams).then(response => {
            this.oaBusinessTravelList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            userId: undefined,
            nickName: undefined,
            type: undefined,
            method: undefined,
            placeDeparture: undefined,
            destination: undefined,
            goOff: undefined,
            endTimes: undefined,
            money: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.oaBusinessTravelForm.init(null)
            this.$refs.oaBusinessTravelForm.form.userId = this.$store.state.user.userId
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.oaBusinessTravelForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delOaBusinessTravel(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
      this.downLoadExcel('/travel/oaBusinessTravel/export', this.queryParams)
    },
    initDict() {
      // 出差类型
      this.getDicts('oa_business_travel_type').then(response => {
        this.typeOptions = response.data
      })
      // 出差方式
      this.getDicts('oa_business_travel_methods').then(response => {
        this.methodsOptions = response.data
      })
      // 出差方式
      this.getDicts('destination_type').then(response => {
        this.destinations = response.data
      })
    }
  }
}
</script>
